package com.pjedu.springbootrestful04.web;

import com.pjedu.springbootrestful04.entity.User;
import com.pjedu.springbootrestful04.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author 汪洋
 * @Description
 */
@RestController
public class UserController {
    @Resource
    private UserService userService;

    // @RequestMapping("findAll")
    @GetMapping("user")
    public Object findAll(){
        return userService.findAll();
    }

    // @RequestMapping("findById")
    @GetMapping("user/{uid}")
    public Object findById(@PathVariable("uid") Integer uid){
        return userService.findById(uid);
    }

    // @RequestMapping("findAllByConditions")
    @PostMapping("findUser")
    public Object findAllByConditions(@RequestBody User user){
        return userService.findAllByConditions(user);
    }

    // @RequestMapping("findUsersLikeUsernames")
    @GetMapping("user/username/{username}")
    public Object findUsersLikeUsernames(@PathVariable("username") String username){
        return userService.findUsersLikeUsernames(username);
    }
    @PostMapping("user")
    public Object insertUser(@RequestBody User user) {
        return userService.insertUser(user);
    }

    @PutMapping("user")
    public Object updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @DeleteMapping("user/{uid}")
    public Object deleteUserById(@PathVariable("uid") Integer uid) {
        return userService.deleteUserById(uid);
    }
}
